package com.question.task;

import com.question.constant.QuestionConstant;
import com.question.pojo.dto.QuestionPageDTO;
import com.question.pojo.dto.UserQuestionDTO;
import com.question.service.IQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * redis缓存预热 定时任务
 */
@Slf4j
@Component
public class CacheWarmUpTask {

    @Autowired
    private IQuestionService questionService;

    // 每天9点自动预热部分题目数据
    @Scheduled(cron = "0 0 9 * * ?")
    public void warmUpCache(){
        log.info("定时任务：预热redis缓存题目数据");
        UserQuestionDTO userQuestionDTO = new UserQuestionDTO();
        userQuestionDTO.setQuestionType(QuestionConstant.CHOICE);
        questionService.listAllQuestions(userQuestionDTO);

        QuestionPageDTO questionPageDTO = new QuestionPageDTO();
        questionPageDTO.setQuestionType(QuestionConstant.CHOICE);
        questionService.listPage(questionPageDTO);
    }

}
